﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        public void myOrder(int[] arr)//从大到小排序
        {
            var nums =
                from n in arr
                orderby n descending
                select n;
            int[] orderedArr = nums.ToArray();
            for(int i = 0; i < orderedArr.Length; i++)
            {
                myOrderBox.Text += (orderedArr[i].ToString() + "  ");
                if (i % 10 == 9)//每行打印10个整数
                {
                    myOrderBox.Text += "\r\n";
                }
            }
            
        }
        public void function(int[] arr)//求和以及平均值
        {
            int total = arr.Sum();
            double aver = arr.Average();
            myAddition.Text += total.ToString();
            myAverage.Text += aver.ToString();
        }
        public void clear()
        {
            myOrderBox.Text = null;
            myAddition.Text = null;
            myAverage.Text = null; 
        }
        private void button1_Click(object sender, EventArgs e)
        {
            clear();
            Random random = new Random();
            int[] vs = new int[100];
            for(int i = 0; i < vs.Length; i++)
            {
                vs[i] = random.Next(1000);//随机生成0到1000之间的整数，不含1000
            }
            myOrder(vs);
            function(vs);
        }
    }
}
